import {
	useRouter
} from 'vue-router'


import WS from "@/utils/websocket";
export function useLogout() {
  const router = useRouter()
  
  const logout = async () => {
    try {
      localStorage.removeItem('token')
      if (WS?.connected) WS.wsClose()
      await router.replace('/')
      return Promise.resolve() // 显式返回成功状态
    } catch (err) {
      return Promise.reject(err) // 捕获并传递异常
    }
  }

  return { logout }
}